const App = {
  // mixins: [Query], //配置文件，路径/utils/mixins.js
  data() {
    return {
      selectedYear: new Date().getFullYear().toString(),
      monthColors: [
        "#e85858",
        "#f09ab2",
        "#9fbf6a",
        "#6fbbc8",
        "#a79ecb",
        "#f7ac69",
        "#ea5859",
        "#f19ab2",
        "#9fbf6a",
        "#6fbbc7",
        "#a79ecb",
        "#f7ac69",
      ],


      treeData: [], //树的数据
      total: {
        PartyMember: "0",
        PartyOrganization: "0"
      },
      ResultQty: [],
      ResultOrg: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],

    };
  },
  mounted() {

    let _partyOrgan = getCookie('party');

    this.GetParty_MemberAndPartyOrganizationPlan(_partyOrgan);

    this.GetParty_MemberAndPartyOrganizationResult(_partyOrgan);
  },
  computed: {


  },
  methods: {

    GetParty_MemberAndPartyOrganizationPlan(val) {

      //获取党员清单
      $.ajax({
        headers: requestHeaders(),
        url: `${mh}/generalBusiness/generalQueryByTableName`,
        type: "POST",
        data: {
          Data: 'party_member_information',
          Condition: "Row_Status='0' and Party_Organization_SerialNumber in (" + val + ")"
        },
        success: (members) => {
          this.total.PartyMember = members.length;
          this.total.PartyOrganization = val.split(",").length;


          //获取当前年度的各个期间的党员缴费人数
          let _year = this.selectedYear;
          $.ajax({
            headers: requestHeaders(),
            url: `${mh}/generalBusiness/generalQueryBySQLSerialNumber`,
            type: "POST",
            data: {
              SQLSerialNumber: 'SQL_party_fees_count',
              Condition: "",
              ExtensionCondition: window.btoa(unescape(encodeURIComponent(
                "  and Belonginterval like '" + _year + "%' and Party_Organization_SerialNumber in (" + val + ")"
              )))
            },
            success: (data) => {
              let _this = this;
              let _Belonginterval = _year;
              let YearMonth = ''

              //将每个月的缴纳党费的人员数 存入数组
              for (let i = 1; i <= 12; i++) {
                YearMonth = _Belonginterval + "-" + i.toString().padStart(2, '0');
                //data.filter(_data => _data.Belonginterval == YearMonth).length

                const lrows = data?.filter(_data => _data.Belonginterval == YearMonth) ?? []

                if (lrows.length > 0) {
                  _this.ResultQty.push(lrows[0].Qty)
                }
                else {
                  _this.ResultQty.push(0)
                }

              }
              console.log(_this.ResultQty);

            },
            complete: (XMLHttpRequest) => {
              requestPretreatment(XMLHttpRequest);
            },
            dataType: "json",
          });

          $.ajax({
            headers: requestHeaders(),
            url: `${mh}/generalBusiness/generalQueryBySQLSerialNumber`,
            type: "POST",
            data: {
              SQLSerialNumber: 'SQL_party_fees_countOrg',
              Condition: "",
              ExtensionCondition: window.btoa(unescape(encodeURIComponent(
                "  and Belonginterval like '" + _year + "%' and Party_Organization_SerialNumber in (" + val + ")"
              )))
            },
            success: (data1) => {

              let _this = this;
              let _Belonginterval = _year;
              let YearMonth = ''
              //将每个组织每个党员进行初始化
              const Organs = val.split(",")

              for (let i = 0; i < Organs.length; i++) {

                let lResultQrg = [];


                //该组织一共有多少党员
                const OrganMember = members?.filter(member => member.Party_Organization_SerialNumber == Organs[i].slice(1, -1)).length ?? 0;
                for (let j = 1; j <= 12; j++) {
                  YearMonth = _Belonginterval + "-" + j.toString().padStart(2, '0');

                  // const ipay1 = data1.filter(_data => _data.Party_Organization_SerialNumber == Organs[i].slice(1, -1) && _data.Belonginterval == YearMonth);

                  //该组织该月份 一共交费多少人

                  const ipayArray = data1?.filter(_data => _data.Party_Organization_SerialNumber == Organs[i].slice(1, -1) && _data.Belonginterval == YearMonth) ?? [];
                  let ipay = 0;
                  if (ipayArray.length > 0) {
                    ipay = ipayArray[0].Qty;
                  }
                  else {
                    ipay = 0;
                  }


                  if (OrganMember != 0) {
                    if (OrganMember <= ipay) {
                      lResultQrg.push(1)
                    }
                    else {
                      lResultQrg.push(0)

                    }
                  }
                  else {
                    lResultQrg.push(0);
                  }
                }
                // _this.ResultOrg.map((num, index) => num + lResultQrg[index])

                _this.ResultOrg.forEach((num, index) => {
                  _this.ResultOrg[index] = num + lResultQrg[index];
                });

              }


            },
            complete: (XMLHttpRequest) => {
              requestPretreatment(XMLHttpRequest);
            },
            dataType: "json",
          });


        },
        complete: (XMLHttpRequest) => {
          requestPretreatment(XMLHttpRequest);
        },
        dataType: "json",
      });







    },
    GetParty_MemberAndPartyOrganizationResult(val) {


    }




  },
};
const { createApp } = Vue;
const app = createApp(App);
//这种方式是引入全部图标，无需单个引入
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
  app.component(key, component);
}
const ElMessage = ElementPlus.ElMessage;

app.component("yl-monthly-calendar", ylMonthlyCalendar);
app.component("yl-cascader", ylCascader);
app.use(ElementPlus, { locale: zhCn });
app.mount("#app");
